#!/usr/bin/env bash
# Filename: getdevuuid.sh
# a script for get your scsi device's UUID, For redflag linux only.
# Usage: ./getdevuuid.sh device, 
# If the device name is not given, the script will print all the scsi device's UUID.

# check your permisson
if [ $UID != 0 ]; then
    echo "Please run this script as root."
    exit 60
fi

getuuid(){
    local blockid uuid size
	blockid=`udevinfo -q path -n $1`
    uuid=`/sbin/scsi_id -g -s $blockid`
	size=`/sbin/sfdisk -s $1`
    echo "$uuid    $1    $size"
}

# 
if [ -z $1 ]; then
    for node in `sfdisk -s | grep '^/dev/sd[a-z]\{1,\}' | awk -F: '{print $1}'`; do
		getuuid $node
    done
else
    # check your device name
    if echo $1 | grep -q '^/dev/'; then
		getuuid $1
    else
        echo -e "Usage: `basename $0` device \neg: `basename $0` /dev/sda"
        exit 1
    fi
fi
